﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZhimeiSoft.Framework.Common.Enums;
using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.Framework.Client;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Client.App;

namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public partial class frmScheduleInfoAddCustom : FormBase
    {
        private DBEntitySchedule schedule = new DBEntitySchedule();
        private DBEntityScheduleCustom scheduleCustom = new DBEntityScheduleCustom();
        private bool isEditMode = false;
        /// <summary>
        /// 新增预约记录 scheduleInfo 为空是新增
        /// </summary>
        /// <param name="scheduleInfo"></param>
        /// <param name="scheduleInfoCustom"></param>
        /// <param name="customInfo"></param>
        public frmScheduleInfoAddCustom(DBEntitySchedule scheduleInfo, DBEntityScheduleCustom scheduleInfoCustom,
            DBEntityCustomInfo customInfo)
        {
            InitializeComponent();
            if (scheduleInfo != null)
            {
                isEditMode = true;
                this.schedule = (DBEntitySchedule)scheduleInfo.Clone();
                this.scheduleCustom = (DBEntityScheduleCustom)scheduleInfoCustom.Clone();
                appointmentScheduleInfo.initControl(schedule, scheduleCustom);
                this.Text = "修改" + this.Text;
            }
            else
            {
                schedule = new DBEntitySchedule();
                scheduleCustom = new DBEntityScheduleCustom();
                scheduleCustom.CUSTOMID = customInfo.CUSTOMERID;
                appointmentScheduleInfo.initControl(customInfo.CNAME);
            }

            labCustomName.Text = "会员姓名：" + customInfo.CNAME;
            labCustomBirthday.Text = "会员生日：" + customInfo.CBIRTHDAY.ToShortDateString();
            labCustomPhone.Text = "会员电话：" + customInfo.CMOBILEPHONE.Trim();
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            //appointmentScheduleInfo
            bool bState = false;
            string error = string.Empty;
            DBEntityScheduleCustom scheduleCustomNew = new DBEntityScheduleCustom();
            scheduleCustomNew = (DBEntityScheduleCustom)scheduleCustom.Clone();
            if (!appointmentScheduleInfo.getInputScheduleInfo(ref schedule, ref scheduleCustomNew, out error))
            {
                MsgBox.MsgInfo(error);
                return;
            }

            if (isEditMode)
            {
                bState = BussinessProxyManager.Instance.UpdateScheduleCustom(schedule, scheduleCustom, scheduleCustomNew, out error);
            }
            else
            {
                bState = BussinessProxyManager.Instance.InsertScheduleCustom(schedule, scheduleCustomNew, out error);
            }
            if (bState == false)
            {
                MsgBox.MsgInfo(error);
                return;
            }
            MsgBox.MsgInfo("保存成功。");
            this.DialogResult = DialogResult.OK;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            if (!MsgBox.MsgQue("确定要退出吗？"))
            {
                return;
            }
            this.DialogResult = DialogResult.Cancel;
        }
    }
}
